package com.liuhengjia.aiknowledgebase.common;

import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.Schema.RequiredMode;
import lombok.Data;

/**
 * 通用响应类
 *
 * @param <T> 响应泛型
 */
@Data
public class RestResult<T> {

    @Schema(description = "请求成功与否", requiredMode = RequiredMode.REQUIRED)
    private boolean success = true;

    @Schema(description = "提示消息，不返回内容", requiredMode = RequiredMode.REQUIRED)
    private String msg = "";

    @Schema(description = "默认业务代码", requiredMode = RequiredMode.REQUIRED)
    private String code = "0000";

    @Schema(description = "返回内容")
    private T content;

    /**
     * 在不需要响应正文时快速返回正常调用
     *
     * @param <T> 响应泛型
     * @return 通用响应对象
     */
    public static <T> RestResult<T> buildSuccessResult() {
        return new RestResult<>();
    }

    /**
     * 正常 return 调用的结果封装
     *
     * @param content 返回内容
     * @param <T>     响应泛型
     * @return 通用响应对象
     */
    public static <T> RestResult<T> buildSuccessResult(T content) {
        RestResult<T> result = new RestResult<>();
        result.setContent(content);
        return result;
    }

}
